package com.uniknow.app.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.tencent.connect.share.QQShare;
import com.uniknow.app.AppContext;
import com.uniknow.app.R;
import com.uniknow.app.oauth.qq.BaseUiListener;
import com.uniknow.app.oauth.qq.TencentHelper;
import com.uniknow.app.operate.BaseListener;
import com.uniknow.app.operate.WixMessageOperate;
import com.uniknow.app.operate.impl.WixMessageOperateImpl;
import com.uniknow.app.util.StringUtils;
import com.uniknow.app.util.UIHelper;

public class TestActivity extends BaseActivity {
	
private TextView HeaderLeftBtn,HeaderRightBtn;
	
	private Button btn1,sendBtn,sendBtnCustoms,sendBtnTextImage;
	private EditText contentEdit;
	
	private WixMessageOperate messageOperate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
		messageOperate = new WixMessageOperateImpl(mContext);
		initView();
	}
	
	/**
	 * <h1>intiView</h1>
	 * <p>初始化view添加单击监听之类的操作</p>
	 */
	private void initView(){
		//HeaderLeftBtn = (TextView) MainActivity.GetHeadView().findViewById(R.id.header01_btn_left);
		//HeaderRightBtn = (TextView) MainActivity.GetHeadView().findViewById(R.id.header01_btn_right);
		btn1 = (Button)findViewById(R.id.table01test1);
		contentEdit = (EditText)findViewById(R.id.table01context);
		sendBtn = (Button)findViewById(R.id.table01send);		
		sendBtnCustoms = (Button)findViewById(R.id.table01sendCustoms);
		sendBtnTextImage = (Button)findViewById(R.id.table01sendTextImage);
		
		sendBtn.setOnClickListener(BtnClick());
		sendBtnCustoms.setOnClickListener(BtnClick());
		sendBtnTextImage.setOnClickListener(BtnClick());
		HeaderRightBtn.setOnClickListener(BtnClick());
		btn1.setOnClickListener(BtnClick());
	}
	
	/**
	 * 单击事件集合
	 * @param btn<Object>
	 * @return
	 */
	private View.OnClickListener BtnClick(){
		return new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				switch(v.getId()){
				case R.id.table01test1:
					test_tencent_share();
					break;
				case R.id.table01send:
					send();
					break;
				case R.id.table01sendCustoms:
					sendCustoms();
					break;
				case R.id.table01sendTextImage:
					sendTextImage();
					break;
				}
				
			}
		};
	}
	/**
	 * <h1>test_tencent_share</h1>
	 * <p>测试QQ互联登录，分享内容</p>
	 */
	public void test_tencent_share(){
		final Bundle params = new Bundle();
		params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
		params.putString(QQShare.SHARE_TO_QQ_TITLE, "unishow");
		params.putString(QQShare.SHARE_TO_QQ_SUMMARY,  "我正在使用一款unishow(联售)的软件产品，宣传效果非常好，你也快来试试吧！");
		params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,  "http://www.qq.com/news/1.html");
		params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, "http://imgcache.qq.com/qzone/space_item/pre/0/66768.gif");
		params.putString(QQShare.SHARE_TO_QQ_APP_NAME,  "联售科技");
		params.putString(QQShare.SHARE_TO_QQ_EXT_INT,  "其他附加功能");
		TencentHelper.getInstance(mContext).getmTencent().shareToQQ((Activity) mContext, params, new BaseUiListener((Activity)mContext));
	}
	
	/**
	 * <h1>send2wix</h1>
	 * <p>发送文本消息到微信公众帐号</p>
	 */
	public void send(){
		String msg = contentEdit.getText().toString();
		if(StringUtils.isEmpty(msg)){
			UIHelper.ToastMessage(mContext, "发送消息不能为空！");
		}else{
			messageOperate.sendText2All(AppContext.user, msg, new BaseListener(){

				@Override
				public void onSuccess(Object o) {
					// TODO Auto-generated method stub
					UIHelper.ToastMessage(mContext, o.toString());
				}

				@Override
				public void onError(String e) {
					// TODO Auto-generated method stub
					UIHelper.ToastMessage(mContext, e);
				}
				
			});
		}
		
	}
	
	/**
	 * 群发客服消息（微信本身不允许这么做，没有一次给多个用户同时发送客服消息的方法）
	 */
	public void sendCustoms(){
		String msg = contentEdit.getText().toString();
		if(StringUtils.isEmpty(msg)){
			UIHelper.ToastMessage(mContext, "发送消息不能为空！");
		}else{
			messageOperate.sendText(AppContext.user, msg, new BaseListener(){

				@Override
				public void onSuccess(Object o) {
					// TODO Auto-generated method stub
					UIHelper.ToastMessage(mContext, o.toString());
				}

				@Override
				public void onError(String e) {
					// TODO Auto-generated method stub
					UIHelper.ToastMessage(mContext, e);
				}
				
			});
		}
	}
	/**
	 * 发送图文混排消息
	 */
	public void sendTextImage(){
		Intent i = new Intent();
		i.setClass(mContext, TextImageActivity.class);
		mContext.startActivity(i);
	}

}
